package main

import (
	"github.com/kataras/iris/v12"
	"time"
)

type Reply struct {
	ErrCode int         `json:"err_code"`
	ErrInfo string      `json:"err_info"`
	Data    interface{} `json:"data"`
}

type AppItemReply struct {
	Name         string    `json:"name"`
	Url          string    `json:"url"`
	LastModified time.Time `json:"last_modified"`
	Size         uint64    `json:"size"`
}

func ErrorReply(ctx *iris.Context, statusCode int, errCode int, errInfo string) {
	(*ctx).StatusCode(statusCode)
	_, _ = (*ctx).JSON(Reply{
		ErrCode: errCode,
		ErrInfo: errInfo,
		Data:    "",
	})
}

func SuccessReply(ctx *iris.Context, data interface{}) {
	_, _ = (*ctx).JSON(Reply{
		ErrCode: 0,
		ErrInfo: "",
		Data:    data,
	})
}
